<?php
@opcache_reset();
$encodingAesKey = isset($_POST['encodingAesKey'])?trim($_POST['encodingAesKey']):"";//消息加解密Key
$token = isset($_POST['token'])?trim($_POST['token']):"";//消息校验Token
$component_appid = isset($_POST['component_appid'])?trim($_POST['component_appid']):"";//第三方公众平台APPID
$component_appsecret = isset($_POST['component_appsecret'])?trim($_POST['component_appsecret']):"";//第三方公众平台APPSECRET
$api_domain = isset($_POST['api_domain'])?trim($_POST['api_domain']):"";//登录授权的发起页域名

if(!$encodingAesKey||!$token||!$component_appid||!$component_appsecret||!$api_domain){
	exit("参数缺失!!!");
}
$data = array(
	"encodingAesKey"=>$encodingAesKey,
	"token"=>$token,
	"component_appid"=>$component_appid,
	"component_appsecret"=>$component_appsecret,
	"api_domain"=>$api_domain,
);
$fileName = 'config.php';
// 更新数据
if (!file_exists($fileName)) {
    file_put_contents($fileName, '');
}
$content = var_export($data, 1);
$fileContent = <<<ab
<?php
    return {$content};
ab;

$f = fopen($fileName, 'r+');
if (flock($f, LOCK_EX)) {
    ftruncate($f, 0);
    rewind($f); // 必须配合rewind否则写入的json字符串无法解析
    fwrite($f, $fileContent);
    fflush($f); // flush output before releasing the lock
    flock($f, LOCK_UN);
}
fclose($f);
//exit("提交成功!");
?>